<?php
namespace app\common\system\logic;

use app\common\BaseLogic;

class FormLogic extends BaseLogic
{
    public function buildToken($userId)
    {
        $key = $userId;
        $cacheKey = md5($key.time());
        $this->redis->set($cacheKey, $userId, 10800);

        return $cacheKey;
    }

    public function checkToken($token, $userId) {
        $result = true;
        $value = $this->redis->get($token);
        if (empty($value) || $value != $userId) $result = false;

        return $result;
    }

    public function removeToken($token) {
        $this->redis->del($token);
    }
}